package com.wqtz.chechai.view.activities;

import android.app.Dialog;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.BaseActivity;
import com.wqtz.chechai.presenter.BasePresent;
import com.wqtz.chechai.utils.StringUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2017/1/23 11:45
 * 申请放款
 */

public class RequestMoneyActivity extends BaseActivity {
	private static final int REQUESTIDCARDINFO = 10235; //请求身份证信息
	private static final int REQUESTCARTIME = 10236; //请求车辆抵押周期
	private static final int REQUESTPROVINCESORT = 10237; //请求车辆归属地
	@BindView(R.id.iv_back)
	ImageView mIvBack;
	@BindView(R.id.tv_title)
	TextView mTvTitle;
	@BindView(R.id.top)
	RelativeLayout mTop;
	@BindView(R.id.tv_carModel)
	TextView mTvCarModel;
	@BindView(R.id.ll_carName)
	LinearLayout mLlCarName;
	@BindView(R.id.tv_assume)
	TextView mTvAssume;
	@BindView(R.id.ll_should_pay)
	LinearLayout mLlShouldPay;
	@BindView(R.id.ll_carinfo)
	LinearLayout mLlCarinfo;
	@BindView(R.id.tv_car_owner)
	TextView mTvCarOwner;
	@BindView(R.id.ll_id_card)
	LinearLayout mLlIdCard;
	@BindView(R.id.et_phone)
	EditText mEtPhone;
	@BindView(R.id.tv_car_state)
	TextView mTvCarState;
	@BindView(R.id.et_car_num)
	EditText mEtCarNum;
	@BindView(R.id.tv_car_keep_time)
	TextView mTvCarKeepTime;
	@BindView(R.id.ll_time)
	LinearLayout mLlTime;
	@BindView(R.id.tv_notice)
	TextView mTvNotice;
	@BindView(R.id.ll_more)
	LinearLayout mLlMore;
	@BindView(R.id.btn_get_verification)
	Button mBtnGetVerification;
	@BindView(R.id.et_car_color)
	EditText mEtCarColor;
	@BindView(R.id.et_car_key)
	EditText mEtCarKey;
	private Dialog dia;


	@Override
	public void init() {
		ButterKnife.bind(this);
	}

	@Override
	public void loadData() {
	}

	@Override
	public int setContentViews() {
		return R.layout.activity_requestmoney;
	}

	@Override
	public BasePresent createPresenter() {
		return null;
	}


	@OnClick({R.id.iv_back, R.id.ll_id_card, R.id.ll_time, R.id.tv_notice, R.id.btn_get_verification, R.id.tv_car_state})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.iv_back:
				finish();
				break;
			case R.id.ll_id_card: {
				Intent intent = new Intent(this, IdCarInfoActivity.class);
				startActivityForResult(intent, REQUESTIDCARDINFO);
			}
			break;
			case R.id.ll_time: {
				Intent intent = new Intent(this, CarTimeSelectedActivity.class);
				startActivityForResult(intent, REQUESTCARTIME);
			}
			break;
			case R.id.tv_notice:
				mTvNotice.setVisibility(View.GONE);
				mLlMore.setVisibility(View.VISIBLE);
				break;
			case R.id.btn_get_verification:
				view = LayoutInflater.from(this).inflate(R.layout.dialog_waite, null);
				Button confirm = (Button) view.findViewById(R.id.btn_confirm);
				TextView title = (TextView) view.findViewById(R.id.title);
				TextView content = (TextView) view.findViewById(R.id.content);
				if (!StringUtils.isEmpty(mEtPhone.getText().toString()) && StringUtils.isValidCellphone(mEtPhone.getText().toString())) {
					title.setText("提交成功");
					content.setText("等待风控审核");
				} else {
					title.setText("提交失败");
					content.setText("请检查内容是否有误");
				}
				confirm.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						dia.dismiss();
					}
				});
				AlertDialog.Builder builder = new AlertDialog.Builder(this);
				builder.setView(view);
				dia = builder.create();
				dia.show();
				break;
			case R.id.tv_car_state: {
				Intent intent = new Intent(this, ProVinceSortActivity.class);
				startActivityForResult(intent, REQUESTPROVINCESORT);
			}
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
				case REQUESTCARTIME: {
					if (data.getIntExtra("days", 0) == 30) {
						mTvCarKeepTime.setText("一个月");
					} else {
						mTvCarKeepTime.setText(data.getIntExtra("days", 0) + "天");
					}
				}
				break;
				case REQUESTIDCARDINFO: {
				}
				break;
				case REQUESTPROVINCESORT: {
					mTvCarState.setText(data.getStringExtra("sort"));
				}
				break;
			}
		}

	}

	@Override
	protected void onResume() {
		super.onResume();
		activitys.add(this); //添加当前的activity
	}
}
